<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>SetFileTime</title>
<meta http-equiv="Content-Type" Content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../styles/styles.css">
<script language="javascript" src='../links.js' type="text/javascript"></script>
</head>
<body>

<h1>SetFileTime</h1>
<div class=navbar>
<a href="../index.html">main</a> |
<a href="../structures/index.html">structures</a> |
<a href="index.html">win32 structures</a>
</div>

<div class=shortdescr>
The <strong>SetFileTime</strong> function sets the date and time that a file was created,
last accessed, or last modified.</div>

<pre class=syntax>
BOOL SetFileTime(
  HANDLE hFile,
  CONST FILETIME *lpCreationTime,
  CONST FILETIME *lpLastAccessTime,
  CONST FILETIME *lpLastWriteTime
);
</pre>

<h3>Parameters</h3>
<div class=descr>

    <div class=dfn>hFile</div>
    <div class=dfndescr>Handle to the file for which to set the dates and times. The file handle must have been created with GENERIC_WRITE access to the file.</div>
    <div class=dfn>lpCreationTime</div>
    <div class=dfndescr>Pointer to a <a href="filetime.html">FILETIME</a> structure that contains the date
and time the file was created. This parameter can be NULL if the application does not need to set this
information.</div>
    <div class=dfn>lpLastAccessTime</div>
    <div class=dfndescr>Pointer to a <a href="filetime.html">FILETIME</a> structure that contains the date
and time the file was last accessed. The last access time includes the last time the file was written to,
read from, or (in the case of executable files) run. This parameter can be NULL if the application does
not need to set this information.</div>
    <div class=dfn>lpLastWriteTime</div>
    <div class=dfndescr>Pointer to a <a href="filetime.html">FILETIME</a> structure that contains the date
and time the file was last written to. This parameter can be NULL if the application does not want to set
this information.</div>

</div>

<h3>Return value</h3>
<div class=descr>
  <p>If the function succeeds, the return value is nonzero.<br>
  If the function fails, the return value is zero.
  To get extended error information, call <a href="win32/GetLastError">GetLastError</a>.</p>
</div>

<h3>Remarks</h3>
<div class=descr>
  <p>The FAT and NTFS file systems support the file creation, last access, and last write time
     values.</p>
  <p>The file time precision can vary depending on operating system, file system, network configuration.
See remarks for the <a href="filetime.html#precise">FILETIME</a> for details.</p>

</div>

<h3>Example</h3>
<div class=descr>
The following example sets the last-write time for a file to the current system time.
  <pre class=code>BOOL SetFileToCurrentTime(HANDLE hFile)
{
  FILETIME ft;
  SYSTEMTIME st;

  GetSystemTime(&amp;st);                 // gets current time
  SystemTimeToFileTime(&amp;st, &amp;ft);     // converts to file time format
  return SetFileTime(hFile,           // sets last-write time for file
              (LPFILETIME) NULL, (LPFILETIME) NULL, &amp;ft);
}
</pre>
</div>


<div class=see>See also:</div><div class=seecont>
<a href="filetime.html">FILETIME</a>,
<a href="win32/GetFileSize">GetFileSize</a>,
<a href="getfiletime.html">GetFileTime</a>,
<a href="win32/GetFileType">GetFileType</a>
</div>

</body>
</html>